<?
include_once("/var/www/html/new/com.inc.php");
if($_REQUEST['action']=='all'){
    include 'class/Member.php';
    include 'common/area.inc.php';
    $ac=$GLOBALS['_ac'];
    $pw=$GLOBALS['_pw'];
    $s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
	
	$saleScene = false;
	$get_account_group = "select group_id from pft_member where id={$_SESSION['sid']} limit 1";
	$GLOBALS['le']->query($get_account_group);
	$GLOBALS['le']->fetch_assoc();
	$group_id = $GLOBALS['le']->f('group_id');
	if($group_id==4) $saleScene = true;// 云顶允许打包现场支付


    $mem = new Member($s, $_SESSION['memberID']);
    $flag = false;
    $post_url = 'prod_edits.html?type=f';

    $prods[1]=$mem->salePros();// 获取门票

	
    $tmp = $save = $ticket = array();
    $sortType='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ(';
    $fids = array();
    $count = 0;
    // print_r($prods);exit;
    $Y_m_d = date('Y-m-d');
    for($i=0;$i<strlen($sortType);$i++){
        foreach($prods[1] as $k=>$val){
           	// 现场支付允许打包
            if($val['p_type']=='F' || $val['p_type']=='B' || $val['sync_status']==2) continue;
            if($val['pay']=='0' && !$saleScene) continue;

			if($sortType[$i]==$val['py']){
                
                if($_GET['d']){
					print_r($val);
				}	
                $xml = $s->Dynamic_Price_And_Storage($_SESSION['saccount'],$val['pid'],$Y_m_d,1,0,0,$val['sapply_did']);
                if($xml==105){
                    $xml = $s->Dynamic_Price_And_Storage($_SESSION['saccount'],$val['pid'],$Y_m_d,2,0,0,$val['sapply_did']);
                }

                if ($xml==105)  continue;
                $jsprice=(int)simplexml_load_string($xml)->Rec->UUsprice;
                $xml = $s->Dynamic_Price_And_Storage($_SESSION['saccount'],$val['pid'],$Y_m_d,1,1,0,$val['sapply_did']);
                if($xml==105){
                    $xml = $s->Dynamic_Price_And_Storage($_SESSION['saccount'],$val['pid'],$Y_m_d,2,1,0,$val['sapply_did']);
                }
				
                if ($xml==105) continue;
				
                $uprice=(int)simplexml_load_string($xml)->Rec->UUsprice;
                if(!isset($save[$val['lid'].'_'.$val['sapply_did']])){
                    $tmp['p_type'] = $val['p_type'];
                    $tmp['sapply_did'] = $val['sapply_did'];
                    $tmp['title'] = $val['title'];
                    $tmp['py'] = $val['py'];
                    $tmp['lid'] = $val['lid'];
                    $tmp['title']=$val['title'];
                    // 拆分地区
                    $tmp['areas'] = explode('|',$val['area']);
                    $tmp['address']=$areas[$tmp['areas'][1]];
                    $fids[$val['sapply_did']]=$val['sapply_did'];
                    
                    $save[$val['lid'].'_'.$val['sapply_did']]=$tmp;
                    $count = $count + 1;
                }

                $ticket['lid']=$val['lid'];
                $ticket['tid']=$val['tid'];
                $ticket['aid']=$val['sapply_did'];
                $ticket['pid']=$val['pid'];
                $ticket['title']=$val['ttitle'];
                $ticket['jsprice']= $jsprice;
                $ticket['uprice'] = $uprice;
                //$ticket['address']=$val['address'];
                $save[$val['lid'].'_'.$val['sapply_did']]['ticket'][]=$ticket;
                unset($prods[1][$k]);
            }
        }
    }

    if(count($fids)){
        $sql="select id,dname from pft_member where id in (".implode(',',$fids).")";
        $GLOBALS['le']->query($sql);
        $dname = array();
        while($list = $GLOBALS['le']->fetch_assoc()){
            $dname[$list['id']] = $list['dname'];
        }
    }
    
    foreach($save as $k=>$v){
        $save[$k]['apply_dname'] = $dname[$v['sapply_did']];
    }
    $prods[1]=$save;

    $response = array(
        'total'=>$count,
        'code'=>200,
        'lists'=>$save
    );
    
    echo json_encode($response);
    exit;
}
function getPrice($s, $rows, $Y_m_d, $sapply_did) {
    $price = array();
    foreach($rows as $key=>$row) {
        $xml = $s->Dynamic_Price_And_Storage($_SESSION['saccount'],$row['pid'],$Y_m_d,1,0,0,$sapply_did);
        if($xml==105){
            $xml = $s->Dynamic_Price_And_Storage($_SESSION['saccount'],$row['pid'],$Y_m_d,2,0,0,$sapply_did);
        }
        if($xml==105) continue;
        $price[$key]['jsprice']=(int)simplexml_load_string($xml)->Rec->UUsprice;
        
        //从接口获取零售价
        $xml = $s->Dynamic_Price_And_Storage($_SESSION['saccount'],$row['pid'],$Y_m_d,1,1,0,$sapply_did);
        if($xml==105){
            $xml = $s->Dynamic_Price_And_Storage($_SESSION['saccount'],$row['pid'],$Y_m_d,2,1,0,$sapply_did);
        }
        if($xml==105)  continue;
        $price[$key]['uprice']=(int)simplexml_load_string($xml)->Rec->UUsprice;
    }
    return $price;
}
?>